<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/IRequestDetailAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/IConnectionAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/ConnectionFactory.php';

	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];

	class MySqlRequestDetailAccessDao implements IRequestDetailAccessDao {  
		/**
		 * Constructor of the request detail dao
		 */
	 	public function __construct () {}
  
  		/**
		 * Selects all request details
		 */
		public function selectRequestDetails($number, $controlNumber) {
			$connection = ConnectionFactory :: getMySqlConnectionAccessDao();
			$conn = $connection -> openConnection();
			
			$query = "UPDATE REQUEST SET
						  read_status = 'LEIDO'
					  WHERE pk_number = $number
					  AND pk_control_number = $controlNumber";
			
			$sentence = mysql_query($query, $conn);
			
			$query = "SELECT rd.pk_line, CONCAT( p.name, ' (', p.specifications, ')' ) name, 
						  rd.units, rd.quantity, rd.unit_cost, rd.quantity * rd.unit_cost total, 
						  r.tax
					  FROM REQUEST r, REQUEST_DETAIL rd, PRODUCT p
					  WHERE r.pk_number = $number
					  AND r.pk_control_number = $controlNumber
					  AND r.pk_number = rd.pk_fk_number_request
					  AND r.pk_control_number = rd.pk_fk_control_number_request
					  AND rd.pk_fk_code_product_inventory = p.pk_code";
			
			$sentence = mysql_query($query, $conn);
				
			$conn = $connection -> closeConnection($conn);
			
			return $sentence;
		 }
  	}
?>